package com.anyonavinfo.cpaddemo.service.musicplayerservice;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import com.anyonavinfo.cpaddemo.data.musicinfo.source.MusicInfoRepository;
import com.anyonavinfo.cpaddemo.data.musicinfo.source.local.MusicInfoLocalDataSource;


public class PlayMusicService extends Service implements IMusicService {

	private String TAG = "MusicLog";
	private PlayServiceHelper mPlayServiceHelper;

	public class MyBinder extends Binder {
		public PlayMusicService getService() {
			return PlayMusicService.this;
		}
	}

	@Override
	public void onCreate() {
		mPlayServiceHelper=new PlayServiceHelper(MusicInfoRepository.
				getInstance(MusicInfoLocalDataSource.getInstance()));

	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		return START_STICKY;
	}

	@Override
	public IBinder onBind(Intent intent) {
		return new MyBinder();
	}

	@Override
	public void onDestroy() {
		stop();
	}

	@Override
	public void play() {
		Log.i(TAG, "play: ");
		mPlayServiceHelper.play();
	}


	@Override
	public void play(int index) {
		mPlayServiceHelper.play(index);
	}

	@Override
	public void pause() {
		Log.i(TAG, "pause: ");
		mPlayServiceHelper.pause();
	}

	@Override
	public void previous() {
		Log.i(TAG, "previous: ");
		mPlayServiceHelper.previous();
	}

	@Override
	public void next() {
		Log.i(TAG, "next: ");
		mPlayServiceHelper.next();
	}

	@Override
	public void playRandom() {
		mPlayServiceHelper.playRandom();
	}

	@Override
	public int getCurrentPosition(){
		return mPlayServiceHelper.getCurrentPosition();
	}

	@Override
	public void stop() {
		mPlayServiceHelper.stop();
	}

	@Override
	public boolean isPlaying() {
		return mPlayServiceHelper.isPlaying();
	}
}
